package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bjsxt.commons.pojo.BaizhanResult;
import com.bjsxt.mapper.TbItemDescMapper;
import com.bjsxt.mapper.TbItemMapper;
import com.bjsxt.mapper.TbItemParamItemMapper;
import com.bjsxt.pojo.TbItem;
import com.bjsxt.pojo.TbItemParam;
import com.bjsxt.pojo.TbItemParamItem;
import com.bjsxt.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;

/**
 * @author coder_z
 * @date 2023/3/20
 **/
public class DetailServiceImpl implements DetailService {
    @Autowired
    private TbItemMapper tbItemMapper;
    @Autowired
    private TbItemDescMapper tbItemDescMapper;
    @Autowired
    private TbItemParamItemMapper tbItemParamItemMapper;
//    一个商品占用一个redis 一个key--value
    @Cacheable(cacheNames = "com.bjsxt",key = "'item'+#id")
    @Override
    public BaizhanResult showItem(long id) {
        System.out.println("没有执行商品详情缓存");
        TbItem tbItem = tbItemMapper.selectById(id);
        return BaizhanResult.ok(tbItem);
    }

    @Override
    public BaizhanResult showItemDesc(long id) {
        return BaizhanResult.ok(tbItemDescMapper.selectById(id));
    }

    @Override
    public BaizhanResult showItemParamItem(long itemId) {
        QueryWrapper<TbItemParamItem> wrapper = new QueryWrapper<TbItemParamItem>().eq("item_id",itemId);
        return BaizhanResult.ok(tbItemParamItemMapper.selectOne(wrapper));
    }
}
